#ifndef _H_WOP_DOUBLE_PROXY_H_
#define _H_WOP_DOUBLE_PROXY_H_

#include "all_entries.h"
extern HINSTANCE _hInst ;  // this instance is defined in DIVA_MAIN
extern HWND _hWnd ;        // this instance is defined in DIVA_Application

BOOL CALLBACK CompPtvProc(HWND,UINT,WPARAM,LPARAM);
extern WOP_Entry* currentEntry;
extern xMappingTree* mTree;
/**
	hyt - 09/09/28 新增WOP_Double_Proxy
		  09/10/05 follows the modification as WOP_Int_Proxy
**/

class WOP_Double_Proxy : public WOP_Entry{
private:
	double _val;
	float _valf;
	int _vali;
	WOP_Double_Entry* _en;
	WOP_Double_Proxy(){}
public:
	WOP_Double_Proxy(WOP_Double_Entry* en){
		this->_en = en;
		init(*(en->getNamePtr()),en->getParent());
	}
	double* getDoubleValAddr() { return &_val ; }
	float* getFloatValAddr() {return &_valf;}
	int* getIntValAddr() {return &_vali;}
	WOP_Double_Entry* getEntry() {return this->_en;}
	string getTypeStr() { return std::string("double"); }
	
	virtual void setVal(string s){
		this->_en->setVal(s);
		this->_value = s;
	}
	virtual void setAddr(string s){
		this->_en->setAddr(s);
		this->_addr = s;
	}
	virtual void setVarType(string s){
		this->_en->setVarType(s);
		this->_vartype = s;
	}
	/* added by ypc */
	virtual void setName(string name) {	
		this->_en->setName(name);
		this->_name = name ;
	}
	virtual void setFrom(WOP_Entry *s){		
		this->_en->setFrom(s);
		this->_from = s;
	}
	virtual void setDescentFrom(WOP_Entry * from){
		this->_en->setDescentFrom(from);
		if (from != NULL) {
			if (from->isTop()) 
				this->_descentfrom = from ;
			else  
				this->_descentfrom = from->getDescentFrom();
		}
	}
	virtual void setTop(bool t){		
		this->_en->setTop(t);
		_top = t;
	}
	virtual void setUpdated(bool t){		
		this->_en->setUpdated(t);
		this->_updated = t;
	}
	virtual void setChanged(bool t){		
		this->_en->setChanged(t);
		this->_changed = t;
	}
	virtual void setScope(bool t){		
		this->_en->setScope(t);
		this->_inscope = t;
	}

	virtual bool update(){
		bool real_en_update;
		real_en_update = _en->update();
		if(real_en_update){
			this->_val = *(_en->getDoubleValAddr());
			this->_valf = *(_en->getFloatValAddr());
			this->_vali = *(_en->getIntValAddr());
			this->_value = _en->getVal();
		}
		this->_changed = real_en_update;
		return this->_changed;
	}
	void updateProxyValue(string s){
		double value ;
		_value = s ;
		if(from_string<double>(value, std::string(_value), std::boolalpha)) {
			_val = value ;
			_valf = (float) _val ;
			_vali = (int)_val;
			this->_changed = true;
		}else assert(false);
	}
	virtual void updateRealValue(string s) {
		double value ;
		_value = s ;
		if(from_string<double>(value, std::string(_value), std::boolalpha)) {
			_val = value ;
			_valf = static_cast< float >( _val );
			_vali = static_cast< int >( _val );
		} else assert(false);
	}
};
#endif